﻿using System;
using ZX.BLL.Extend;
using System.Data.SqlClient;
using System.Data;

namespace ZX.CRM.Bussiness
{
    public class BCrmCustomerShare : BaseBussnies
    {
        /// <summary>
        /// 删除共享客户
        /// </summary>
        /// <param name="Customerid"></param>
        /// <param name="adduser"></param>
        /// <returns></returns>
        public string ExecDeleteCrmProc(Guid Customerid, Guid adduser)
        {
            string returnstr = "";
            SqlParameter Customerids = new SqlParameter("@CustomId", SqlDbType.UniqueIdentifier, 50);
            Customerids.Direction = ParameterDirection.Input;
            Customerids.Value = Customerid;
            SqlParameter AddUsers = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
            AddUsers.Direction = ParameterDirection.Input;
            AddUsers.Value = adduser;          
            SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
            ReturnValue.Direction = ParameterDirection.Output;
            IDataParameter[] parameters = new IDataParameter[] {Customerids,AddUsers,ReturnValue};
            int IResult = 0;
            ZX.DAL.DBExtend.DbSql ExecPro = new DAL.DBExtend.DbSql();
            returnstr = ExecPro.RunProcedureReturnString("sp_DeleteCrmShareCustome", parameters, out IResult);
            return returnstr;
        }
        /// <summary>
        /// 共享客户
        /// </summary>
        /// <param name="Customerid"></param>
        /// <param name="Fromuserid"></param>
        /// <param name="touserid"></param>
        /// <param name="adduser"></param>
        /// <param name="itype"></param>
        /// <returns></returns>
        public string ExecProc(Guid Customerid,Guid Fromuserid, Guid touserid,Guid  adduser,int itype)
        {
            string returnstr = "";
            SqlParameter Customerids = new SqlParameter("@CustomId", SqlDbType.UniqueIdentifier, 50);
            Customerids.Direction = ParameterDirection.Input;
            Customerids.Value = Customerid;
            SqlParameter FromUserIds = new SqlParameter("@FromUserId", SqlDbType.UniqueIdentifier, 50);
            FromUserIds.Direction = ParameterDirection.Input;
            FromUserIds.Value = Fromuserid;
            SqlParameter ToUserIds = new SqlParameter("@ToUserId", SqlDbType.UniqueIdentifier, 50);
            ToUserIds.Direction = ParameterDirection.Input;
            ToUserIds.Value = touserid;
            SqlParameter AddUsers = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
            AddUsers.Direction = ParameterDirection.Input;
            AddUsers.Value = adduser;
            SqlParameter iTypes = new SqlParameter("@iType", SqlDbType.Int, 50);
            iTypes.Direction = ParameterDirection.Input;
            iTypes.Value = itype;         
            SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
            ReturnValue.Direction = ParameterDirection.Output;
            IDataParameter[] parameters = new IDataParameter[] { Customerids, FromUserIds, ToUserIds, AddUsers, iTypes, ReturnValue };
            int IResult = 0;
            ZX.DAL.DBExtend.DbSql ExecPro = new DAL.DBExtend.DbSql();
            returnstr = ExecPro.RunProcedureReturnString("sp_AddCrmShareCustomer", parameters, out IResult);
            return returnstr;
        }

        /// <summary>
        /// 删除共享客户(客户分配)
        /// </summary>
        /// <param name="Customerid"></param>
        /// <param name="adduser"></param>
        /// <returns></returns>
        public string ExecDeleteCrmProcCustomerInfo(Guid Customerid, Guid adduser)
        {
            string returnstr = "";
            SqlParameter Customerids = new SqlParameter("@CustomId", SqlDbType.UniqueIdentifier, 50);
            Customerids.Direction = ParameterDirection.Input;
            Customerids.Value = Customerid;
            SqlParameter AddUsers = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
            AddUsers.Direction = ParameterDirection.Input;
            AddUsers.Value = adduser;
            SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
            ReturnValue.Direction = ParameterDirection.Output;
            IDataParameter[] parameters = new IDataParameter[] { Customerids, AddUsers, ReturnValue };
            int IResult = 0;
            ZX.DAL.DBExtend.DbSql ExecPro = new DAL.DBExtend.DbSql();
            returnstr = ExecPro.RunProcedureReturnString("sp_DeleteCrmShareCustomeInfo", parameters, out IResult);
            return returnstr;
        }
        /// <summary>
        /// 共享客户(客户分配)
        /// </summary>
        /// <param name="Customerid"></param>
        /// <param name="Fromuserid"></param>
        /// <param name="touserid"></param>
        /// <param name="adduser"></param>
        /// <param name="itype"></param>
        /// <returns></returns>
        public string ExecProcCustomerInfo(Guid Customerid, Guid Fromuserid, Guid touserid, Guid adduser, int itype)
        {
            string returnstr = "";
            SqlParameter Customerids = new SqlParameter("@CustomId", SqlDbType.UniqueIdentifier, 50);
            Customerids.Direction = ParameterDirection.Input;
            Customerids.Value = Customerid;
            SqlParameter FromUserIds = new SqlParameter("@FromUserId", SqlDbType.UniqueIdentifier, 50);
            FromUserIds.Direction = ParameterDirection.Input;
            FromUserIds.Value = Fromuserid;
            SqlParameter ToUserIds = new SqlParameter("@ToUserId", SqlDbType.UniqueIdentifier, 50);
            ToUserIds.Direction = ParameterDirection.Input;
            ToUserIds.Value = touserid;
            SqlParameter AddUsers = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
            AddUsers.Direction = ParameterDirection.Input;
            AddUsers.Value = adduser;
            SqlParameter iTypes = new SqlParameter("@iType", SqlDbType.Int, 50);
            iTypes.Direction = ParameterDirection.Input;
            iTypes.Value = itype;
            SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
            ReturnValue.Direction = ParameterDirection.Output;
            IDataParameter[] parameters = new IDataParameter[] { Customerids, FromUserIds, ToUserIds, AddUsers, iTypes, ReturnValue };
            int IResult = 0;
            ZX.DAL.DBExtend.DbSql ExecPro = new DAL.DBExtend.DbSql();
            returnstr = ExecPro.RunProcedureReturnString("sp_AddCrmShareCustomerInfo", parameters, out IResult);
            return returnstr;
        }
        /// <summary>
        /// 共享客户(客户分配)
        /// </summary>
        /// <returns>1成功，0失败</returns>
        public string ExecProcSetPrivateNum(Guid touserid, Guid adduser, int num)
        {
            string returnstr = "";
            SqlParameter ToUserIds = new SqlParameter("@UserID", SqlDbType.UniqueIdentifier, 50);
            ToUserIds.Direction = ParameterDirection.Input;
            ToUserIds.Value = touserid;
            SqlParameter PrivateNum = new SqlParameter("@PrivateNum", SqlDbType.Int, 4);
            PrivateNum.Direction = ParameterDirection.Input;
            PrivateNum.Value = num;
            SqlParameter AddUsers = new SqlParameter("@AddUser", SqlDbType.UniqueIdentifier, 50);
            AddUsers.Direction = ParameterDirection.Input;
            AddUsers.Value = adduser;
            SqlParameter ReturnValue = new SqlParameter("@ReturnValue", SqlDbType.NVarChar, 50);
            ReturnValue.Direction = ParameterDirection.Output;
            IDataParameter[] parameters = new IDataParameter[] { ToUserIds,PrivateNum, AddUsers,  ReturnValue };
            int IResult = 0;
            ZX.DAL.DBExtend.DbSql ExecPro = new DAL.DBExtend.DbSql();
            returnstr = ExecPro.RunProcedureReturnString("sp_SetCrmPrivateNum", parameters, out IResult);
            return returnstr;
        }
    }
}
